package com.jinxiangyang.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jinxiangyang.annotation.OperateLog;
import com.jinxiangyang.domain.vo.LiveCourcseVo;
import com.jinxiangyang.domain.vo.LiveCourseVo;
import com.jinxiangyang.service.LiveCourseService;
import com.jinxiangyang.utils.enums.BusinessType;
import com.jinxiangyang.utils.enums.OperatorType;
import com.jinxiangyang.utils.result.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 直播课程表 前端控制器
 * </p>
 *
 * @author jinxiangyang
 * @since 2023-08-12
 */
@RestController
@RequestMapping("/liveCourse")
@Api(tags = "直博课程接口")
public class LiveCourseController {




    @Autowired
    public LiveCourseService liveCourseService;


    @GetMapping("/{id}")
    @ApiOperation("根据id查询直播信息")
    @OperateLog(title = "直博课程接口",businessType = BusinessType.OTHER,operatorType = OperatorType.TEACHER)
    public AjaxResult getLiveCourcseById(@PathVariable Integer id){
        if(id==0){
            return  AjaxResult.error("参数错误");
        }
        LiveCourcseVo liveCourseByCourseId = liveCourseService.getLiveCourseByCourseId(id);
        if(liveCourseByCourseId==null){
            return  AjaxResult.error("未查询到结果");
        }
        return AjaxResult.success(liveCourseByCourseId);
    }

    @PostMapping("/{currentPage}/{pageSize}")
    @ApiOperation("分页查询直播课程")
    public AjaxResult getLiveCourseByPage(@PathVariable Long currentPage,@PathVariable Long pageSize,@RequestBody LiveCourseVo liveCourseVo){
        IPage<LiveCourseVo> liveCourseByPage;
        if (liveCourseVo == null){
            liveCourseByPage = liveCourseService.getLiveCourseByPage(currentPage, pageSize);
        }else {
            liveCourseByPage = liveCourseService.getLiveCourseByPage(currentPage, pageSize,liveCourseVo);
        }
        return AjaxResult.success(liveCourseByPage);
    }

    @PostMapping
    @ApiOperation("添加直播")
    public AjaxResult addLiveCourse(@RequestBody LiveCourseVo liveCourseVo){
        boolean flag = liveCourseService.addLiveCourse(liveCourseVo);
        if (flag){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @PostMapping("/upload")
    @ApiOperation("头像上传")
    public AjaxResult avatarUpload(MultipartFile file) {
        String url = liveCourseService.avatarUpload(file);
        return AjaxResult.success("上传成功", url);
    }


}

